#!/usr/bin/env node

const http = require('http');
const log = console.log;
http.createServer((req,res)=>{
  log(`${req.method} ${req.url} HTTP/${req.httpVersion}`);
  log(req.headers);
  // log(req.headers.host);
  // log(req.headers['user-agent']);
  // log(req.headers['content-type']);
  const {
    host, 
    authorization,
    'user-agent': userAgent, 
    'content-type': contentType
  } = req.headers;
  const userInfo = atob(authorization.slice(6));
  const [userName, password] = userInfo.split(':');
  log({host, userAgent, contentType, userName, password});
  log();
  //表格打印
  // console.table({host, userAgent, contentType});
  res.end('ok');
}).listen(8080);

// 最后运行curl -H "Content-Type:appliction/json" http://suziyi:ddd@localhost:8080